Imports System.Drawing.Drawing2D

Public Class UcnPenPopupControl
    'represents PopupContainerControl for setting a MindFusion.Drawing.Pen

#Region "Properties"
#Region "Public properties"
    'Pen - result of this "control"
    Public ReadOnly Property Result() As MindFusion.Drawing.Pen
        Get
            Return New MindFusion.Drawing.Pen(ceColor.Color, edtWidth.Value)
        End Get
    End Property
#End Region
#End Region
#Region "Constructors"
    Sub New()

        ' This call is required by the Windows Form Designer.
        InitializeComponent()

        ' Add any initialization after the InitializeComponent() call.
        Init(MFPenVirginCreator(Color.Black, 1))
    End Sub

    Sub New(ByVal IoPen As MindFusion.Drawing.Pen)

        ' This call is required by the Windows Form Designer.
        InitializeComponent()
        ' Add any initialization after the InitializeComponent() call.

        Init(IoPen)
    End Sub
#End Region
#Region "Events handler"
    'repainting of preview 
    Private Sub PopupContainerControl_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles PopupContainerControl.Paint
        PaintPreview()
    End Sub
    'repainting of preview 
    Private Sub edtWidth_EditValueChanging(ByVal sender As Object, ByVal e As DevExpress.XtraEditors.Controls.ChangingEventArgs) Handles edtWidth.EditValueChanging
        PaintPreview()
    End Sub
    'repainting of preview 
    Private Sub edtWidth_EditValueChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles edtWidth.EditValueChanged
        PaintPreview()
    End Sub
#End Region
#Region "Subs"
    'initialization of controls
    Public Sub Init(ByVal IoPen As MindFusion.Drawing.Pen)
        If IoPen IsNot Nothing Then
            ceColor.Color = IoPen.Color
            edtWidth.Value = IoPen.Width
        Else
            Debug.Print("UcnPenPopupControl.Init prazdny objekt")
            ceColor.Color = Color.Black
            edtWidth.Value = 1
        End If
    End Sub
    'painting of preview
    Private Sub PaintPreview()
        Dim LoHwnd As IntPtr = PopupContainerControl.Handle
        Dim LoGraphics As System.Drawing.Graphics = Graphics.FromHwnd(LoHwnd)

        Dim LoRectangleF As RectangleF = SDRectangleFVirginCreator(200, 20, 90, 100)
        Dim LoColor As Color = ceColor.Color
        Dim LnWidth As Single = edtWidth.Value
        Dim LiX, LiY As Integer
        LiX = 110
        LiY = 75
        'clearing a area
        LoGraphics.DrawLine(SDPenVirginCreator(PopupContainerControl.BackColor, 20), LiX, LiY, LiX + 80, LiY)
        LoGraphics.DrawLine(SDPenVirginCreator(LoColor, LnWidth), LiX, LiY, LiX + 80, LiY)
    End Sub
#End Region

End Class
